package com.ymatou.iapi.live.testcase;

import java.util.ArrayList;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.live.parameter.GetHasCouponsBySellerIdsBean;
import com.ymatou.iapi.live.service.GetHasCouponsBySellerIdsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.BuyerCallService;
import com.ymttest.utils.EnvSetup;

public class Ts_GetHasCouponsBySellerIds {
	
	private static GetHasCouponsBySellerIdsBean getHasCouponsBySellerIdsBean;
	private static GetHasCouponsBySellerIdsCall getHasCouponsBySellerIdsCall;
	public BuyerCallService buyerCallService = new BuyerCallService();
	private static int sellerId = Integer.parseInt(EnvSetup.getData("zhangyi_seller002_id"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手是否有优惠券");
	}

	@Before
	public void caseUp() throws Exception {
		getHasCouponsBySellerIdsBean = new GetHasCouponsBySellerIdsBean();
		getHasCouponsBySellerIdsCall = new GetHasCouponsBySellerIdsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getHasCouponsBySellerIdsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetHasCouponsBySellerIds_001() {
		 Logger.start(true,"验证接口数据是否正常");
		 try {
			 Boolean except = false;
			 
			 if (buyerCallService.getSellerCouponList(sellerId).length() > 0)
				 except = true;
			 
			 ArrayList<Integer> list = new ArrayList<Integer>();
			 list.add(sellerId);
			 
			 getHasCouponsBySellerIdsBean.setSellerIds(list);
			 
			 getHasCouponsBySellerIdsCall.setData(getHasCouponsBySellerIdsBean);
			 getHasCouponsBySellerIdsCall.callService();
			 
			 JSONObject hasCouponObj = new JSONObject(getHasCouponsBySellerIdsCall.getCouponsList().get(0).toString());
			 Logger.verifyEquals(except, hasCouponObj.getBoolean("hasCoupon"), "验证hasCoupon是否为true");
			 
		 } catch (Exception e) {
			 Logger.fail(e);
		 }
	 }
}
